package practite.sort;

import java.util.Arrays;
import java.util.Random;

/**
 插入排序
 **/

public class InsertionSort {
    public static void main(String[] args) {
        int[] array = getRandomArray();
        System.out.println(Arrays.toString(array));

        int max = 0;
        for (int i = 1; i < array.length; i++) {
            for (int j = i-1; j >= 0; j--) {
                if (array[j+1]<array[j]){
                    max = array[j+1];
                    array[j+1] = array[j];
                    array[j] = max;
                    System.out.println(Arrays.toString(array));
                }
            }
            System.out.println();
        }
        System.out.println(Arrays.toString(array));

    }

    //随机数
    public static int getRandom(){
        Random random = new Random();
        int a = random.nextInt(100)+1;
        return a;
    }
    //创建随机数组
    public static int[] getRandomArray(){
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = getRandom();
        }
        return a;
    }
}
